﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ManageBanking.Areas.Admin.Models
{
    public class SearchModels
    {
        private OnlineBankingDataContext olbk = new OnlineBankingDataContext();

        /****************** Search *************/
        public List<Username> SearchUserID(int IdUsername, out int totalUsername)
        {
            totalUsername = olbk.Usernames.Where(u => u.IdUsername == IdUsername && u.IdTypeUser == 2).Count();
            return olbk.Usernames.Where(u => u.IdUsername == IdUsername && u.IdTypeUser == 2).ToList();
        }

        public List<Username> SearchUserName(string name, out int totalUsername)
        {
            totalUsername = olbk.Usernames.Where(u => u.Username1.Trim().ToLower().Equals(name.Trim().ToLower()) && u.IdTypeUser == 2).Count();
            return olbk.Usernames.Where(u => u.Username1.Trim().ToLower().Equals(name.Trim().ToLower()) && u.IdTypeUser == 2).ToList();
        }

        public List<Username> SearchUserAll(out int totalUsername)
        {
            totalUsername = olbk.Usernames.Where(u => u.IdTypeUser == 2).Count();
            return olbk.Usernames.Where(u=> u.IdTypeUser == 2).ToList();
        }

        public List<Username> SearchUserDate(DateTime date, out int totalUsername)
        {

            totalUsername = olbk.Usernames.Where(u => u.IdTypeUser == 2 && u.DateBirth == date).Count();
            return olbk.Usernames.Where(u => u.IdTypeUser == 2 && u.DateBirth == date).ToList();
        }

        /******************end Search *************/



        /*************** Search Request Admin ***************/
        public List<RequestAdmin> SearchRequestAdminUsername(int Username, out int totalUsername)
        {
            totalUsername = olbk.RequestAdmins.Where(r => r.IdUsername==Username).Count();
            return olbk.RequestAdmins.Where(r => r.IdUsername==Username).ToList();
        }


        public List<RequestAdmin> SearchRequestAdminDate(DateTime DateCreate, out int totalUsername)
        {
            totalUsername = olbk.RequestAdmins.Where(r => r.DateCreate == DateCreate).Count();
            return olbk.RequestAdmins.Where(r => r.DateCreate == DateCreate).ToList();
        }


        public List<RequestAdmin> SearchRequestAdminSolved(bool Solved, out int totalUsername)
        {
            totalUsername = olbk.RequestAdmins.Where(r => r.Solved == Solved).Count();
            return olbk.RequestAdmins.Where(r => r.Solved == Solved).ToList();
        }

        public List<RequestAdmin> SearchRequestAdminAll(out int totalUsername)
        {
            totalUsername = olbk.RequestAdmins.Count();
            return olbk.RequestAdmins.ToList();
        }

        /*************end Search Request Admin*******************/


        public bool Update(int idusername, string lockuser)
        {
            bool kq = true;
            try
            {
                Username un = olbk.Usernames.Where(u => u.IdUsername == idusername).First();
                un.Lock = Convert.ToBoolean(Convert.ToBoolean(lockuser));
                olbk.SubmitChanges();
            }
            catch
            {
                kq = false;
            
            }
            return kq;

        }
    }
}
